package com.hutou.chuangke.activity;

import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ListView;

import com.hutou.chuangke.Bean.CleanCacheBean;
import com.hutou.chuangke.R;
import com.hutou.chuangke.adapter.CleanCacheAdapter;
import com.hutou.chuangke.uitl.CommonUtils;
import com.hutou.chuangke.widget.SwipeRefreshLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by o on 2017/4/7.
 * 清除缓存
 */

public class CleanCacheActivity extends BaseActivity{
    Toolbar toolbar;
    ListView cleancash_list;
    CleanCacheAdapter cleanCacheAdapter;
    List<CleanCacheBean> list = new ArrayList<>();
    private SwipeRefreshLayout swipeRefresh;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cleancache);
        initView();
    }

    private void initView() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setPadding(0, CommonUtils.getStatusHeight(CleanCacheActivity.this), 0, 0);
        setSupportActionBar(toolbar);
        final ActionBar ab = getSupportActionBar();
        ab.setHomeAsUpIndicator(R.drawable.actionbar_back);
        ab.setDisplayHomeAsUpEnabled(true);
        ab.setTitle("");
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        showQuickControl(false);
        cleancash_list = (ListView) findViewById(R.id.cleancash_list);
        cleanCacheAdapter = new CleanCacheAdapter(CleanCacheActivity.this);
        CleanCacheBean cleanCacheBean = new CleanCacheBean("标题","说明","12M");
        CleanCacheBean cleanCacheBean1 = new CleanCacheBean("标题","说明","12M");
        CleanCacheBean cleanCacheBean2 = new CleanCacheBean("标题","说明","12M");

        list.add(cleanCacheBean);
        list.add(cleanCacheBean1);
        list.add(cleanCacheBean2);

        cleancash_list.setAdapter(cleanCacheAdapter);
        cleanCacheAdapter.setList(list);
        cleanCacheAdapter.notifyDataSetChanged();
        swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
        swipeRefresh.setOnPullRefreshListener(new SwipeRefreshLayout.OnPullRefreshListener() {
            @Override
            public void onRefresh() {
                swipeRefresh.setRefreshing(true);
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        swipeRefresh.setRefreshing(false);
                    }
                },2000);
            }

            @Override
            public void onPullDistance(int distance) {

            }

            @Override
            public void onPullEnable(boolean enable) {

            }
        });

        swipeRefresh.setOnPushLoadMoreListener(new SwipeRefreshLayout.OnPushLoadMoreListener() {
            @Override
            public void onLoadMore() {
//                swipeRefresh.setRefreshing(true);
                swipeRefresh.setLoadMore(true);
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        swipeRefresh.setLoadMore(false);
                    }
                },2000);
            }

            @Override
            public void onPushDistance(int distance) {

            }

            @Override
            public void onPushEnable(boolean enable) {

            }
        });

    }

    Handler handler = new Handler();
}
